//
//  TravelAreaDetailsTableViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/16.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelAreaDetailsTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#import "TravelAreaButtonView.h"

@interface TravelAreaDetailsTableViewCell ()

//照片
@property (nonatomic, retain) UIImageView *imagePic;
//中文label
@property (nonatomic, retain) UILabel *labelChinese;
//英文label
@property (nonatomic, retain) UILabel *labelEnglish;
@end

@implementation TravelAreaDetailsTableViewCell
-(void)dealloc
{
    [_imagePic release];
    [_labelChinese release];
    [_labelEnglish release];
    [_viewOne release];
    [_viewTwo release];
    [_viewThree release];
    [_viewFour release];
    [_model release];
    [super dealloc];
    
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        
        [self createView];
        
    }
    
    return self;
}

-(void)createView
{
    
    self.imagePic = [[UIImageView alloc]init];
  //  self.imagePic.backgroundColor = [UIColor grayColor];
    
    [self addSubview:self.imagePic];
    [_imagePic release];
    
    
    self.labelChinese = [[UILabel alloc]init];
  //  self.labelChinese.backgroundColor =  [UIColor greenColor];
    self.labelChinese.font = [UIFont systemFontOfSize:19 *kWidth];
    self.labelChinese.textColor = [UIColor whiteColor];
    
    
    [self.imagePic addSubview:self.labelChinese];
    [_labelChinese release];
    
    self.labelEnglish = [[UILabel alloc]init];
    
    self.labelEnglish.font = [UIFont systemFontOfSize:17 *kWidth];
    self.labelEnglish.textColor = [UIColor whiteColor];
    
    
   // self.labelEnglish.backgroundColor = [UIColor whiteColor];
    [self.imagePic addSubview:self.labelEnglish];
    [_labelEnglish release];
    
    
    self.viewOne = [[TravelAreaButtonView alloc]initWithLabelStr:@"行程" ImageUrl:@"xingcheng"];
   // self.viewOne.backgroundColor = [UIColor purpleColor];
    
    [self addSubview:self.viewOne];
    [_viewOne release];
    
    
    
    self.viewTwo = [[TravelAreaButtonView alloc]initWithLabelStr:@"旅行地" ImageUrl:@"Travellvxingdi"];
   // self.viewTwo.backgroundColor = [UIColor purpleColor];
    
    [self addSubview:self.viewTwo];
    [_viewTwo release];
    
    
    self.viewThree = [[TravelAreaButtonView alloc]initWithLabelStr:@"专题" ImageUrl:@"travelzhuangti"];
  //  self.viewThree.backgroundColor = [UIColor purpleColor];
    
    [self addSubview:self.viewThree];
    [_viewThree release];
    
    
//    self.viewFour = [[TravelAreaButtonView alloc]initWithLabelStr:@"下载" ImageUrl:@"Travelxiazai"];
//    //self.viewFour.backgroundColor = [UIColor purpleColor];
//    
//    [self addSubview:self.viewFour];
//    [_viewFour release];
//  
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    
    self.imagePic.frame = CGRectMake(5 *kWidth, 0, self.frame.size.width - 10 *kWidth, self.frame.size.height /3 * 2);
    
    self.labelChinese.frame = CGRectMake(5 *kWidth, 10 *kHeight, self.frame.size.width - 10*kWidth, 25*kHeight);
    self.labelEnglish.frame = CGRectMake(self.labelChinese.frame.origin.x, self.labelChinese.frame.size.height + self.labelChinese.frame.origin.y, self.labelChinese.frame.size.width, self.labelChinese.frame.size.height);
    
    self.viewOne.frame = CGRectMake(25 *kWidth, self.imagePic.frame.size.height + 20 *kHeight , 60 *kWidth, self.frame.size.height / 3 - 40 *kWidth);
    [self.viewOne.btn addTarget:self action:@selector(twoAction:) forControlEvents:UIControlEventTouchUpInside];
    self.viewOne.btn.tag =7777;
    
    self.viewTwo.frame = CGRectMake(self.viewOne.frame.size.width + self.viewOne.frame.origin.x + 72.5 *kWidth, self.viewOne.frame.origin.y, self.viewOne.frame.size.width, self.viewOne.frame.size.height);
     [self.viewTwo.btn addTarget:self action:@selector(twoAction:) forControlEvents:UIControlEventTouchUpInside];
      self.viewTwo.btn.tag = 8888;
    
    
    self.viewThree.frame = CGRectMake(self.viewTwo.frame.size.width +self.viewTwo.frame.origin.x + 62.5 *kWidth, self.viewOne.frame.origin.y, self.viewOne.frame.size.width, self.viewOne.frame.size.height);
    [self.viewThree.btn addTarget:self action:@selector(twoAction:) forControlEvents:UIControlEventTouchUpInside];
    self.viewThree.btn.tag = 9999;
    
    
    
//    self.viewFour.frame = CGRectMake(self.viewThree.frame.size.width + self.viewThree.frame.origin.x + 25 *kWidth, self.viewThree.frame.origin.y, self.viewThree.frame.size.width, self.viewThree.frame.size.height);
   
}

-(void)twoAction:(UIButton *)btn
{
    [self.delegate sendToRootViewController:self.model.name_zh_cn ID:self.model.ID tag:btn.tag];
}

-(void)setModel:(TraveAreaModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.imagePic sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"Travel_place"]];

    self.labelChinese.text = model.name_zh_cn;
    self.labelEnglish.text = model.name_en;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
